package com.green.common;

import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;

public class BOSObjectType implements Serializable{

	 private static final long serialVersionUID = -65534L;
	 private transient String strType;
	 private transient int intType;
	  
	 public BOSObjectType(String type)
	  {
	    if (type == null) {
	      throw new IllegalArgumentException("null BOSObjectType.");
	    }
	    type = type.trim();
	    if (type.length() == 4)
	    {
	      this.intType = 0;
	      this.strType = type.intern();
	    }
	    else
	    {
	      assert (type.length() == 8);
	      long parsedLong = 0L;
	      try
	      {
	        parsedLong = Long.parseLong(type, 16);

	        if (parsedLong > 2147483647L)
	          parsedLong = -2147483648L + (parsedLong - 2147483647L - 1L);
	      }
	      catch (NumberFormatException nfe) {
	      }
	      this.intType = (int)parsedLong;
	      if (parsedLong == 0L)
	      {
	        this.strType = type;
	      }
	      else
	      {
	        this.strType = null;
	      }
	    }
	  }
	 
	 public static BOSObjectType create(String type)
	  {
	    BOSObjectType val = new BOSObjectType(type);	         
	    return val;
	  }
	 
	 public void write(DataOutput out) throws IOException
	  {
	    out.writeInt(this.intType);
	    if (this.intType == 0)
	      out.writeUTF(this.strType);
	  }
	 
	 public int hashCode()
	  {
	    if (this.strType != null) {
	      return this.strType.hashCode();
	    }
	    return this.intType;
	  }
}
